// 封装接口函数
import type {
  User,
  CodeType,
  UserInfo,
  PatientList,
  Patient
} from '@/types/user'
import { request } from '../utils/request'

// 密码登录的接口
export const loginByPasswordAPI = (mobile: string, password: string) => {
  return request<User>('/login/password', 'POST', { mobile, password })
}

//获取验证码的接口
export const sendMobileCodeAPI = (mobile: string, type: CodeType) => {
  return request('/code', 'GET', { mobile, type })
}

// 短信登录接口
export const loginByMobileAPI = (mobile: string, code: string) => {
  return request<User>('/login', 'POST', { mobile, code })
}

// 获取用户信息接口
export const getUserInfoAPI = () => {
  return request<UserInfo>('/patient/myUser')
}

// 获患者信息列表
export const getPatientListAPI = () => request<PatientList>('/patient/mylist')

// 添加患者的接口
export const addPatientAPI = (patient: Patient) => {
  return request('/patient/add', 'POST', patient)
}

// 编辑患者信息的接口
export const editPatientAPI = (patient: Patient) => {
  return request('/patient/update', 'PUT', patient)
}

// 删除患者信息的接口
export const delPatientAPI = (id: string) => {
  return request(`/patient/del/${id}`, 'DELETE')
}
// 查询患者详情
export const getPatientDetail = (id: string) =>
  request<Patient>(`/patient/info/${id}`)

/**
 *
 * @returns 未读消息数量
 */
export const getUnreadMessageCount = () =>
  request<number>('/patient/message/unRead/all')
